<template>
    <div>
        <el-dialog title="快递信息" :visible.sync="show">
            <el-form :model="form" :rules="rules" ref="form">
                <el-form-item label="快递公司" :label-width="formLabelWidth" prop="express">
                    <el-select v-model="form.express" placeholder="请选择快递公司">
                        <el-option v-for="item in expressList" :label="item.name" :value="item.express"
                            :key="item.experss"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="快递单号" :label-width="formLabelWidth" prop="express_num">
                    <el-input v-model="form.express_num" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="show = false">取 消</el-button>
                <el-button type="primary" @click="sendBtn('form')">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            show: false,
            order_id: '',
            form: {
                express: '',
                express_num: '',
                id: ''
            },
            rules: {
                express: [
                    { required: true, message: '请选择快递公司', trigger: 'change' }
                ],
                express_num: [
                    { required: true, message: '请选择快递公司', trigger: 'blur' }
                ]
            },
            formLabelWidth: '120px',
            expressList: [
                {
                    name: '圆通',
                    express: 'yto'
                },
                {
                    name: '申通',
                    express: 'sto'
                },
                {
                    name: 'EMS',
                    express: 'ems'
                },
                {
                    name: '顺丰',
                    express: 'sfexpress'
                },
                {
                    name: '中通',
                    express: 'zto'
                },
                {
                    name: '韵达',
                    express: 'yunda'
                },
                {
                    name: '天天',
                    express: 'ttkdxe'
                },
                {
                    name: '百世快递',
                    express: 'htky'
                },
                {
                    name: '邮政包裹',
                    express: 'chinapost'
                },
                {
                    name: '德邦',
                    express: 'deppon'
                },
                {
                    name: '极兔速递',
                    express: 'jtsd'
                },
                {
                    name: '其他',
                    express: 'other'
                },



            ]
        }
    },
    methods: {
        sendBtn(formName) {
            this.$refs[formName].validate((valid) => {
                console.log(this.form)
                if (valid) {
                    if (this.form.id) {
                        this.expressNum(this.form)
                    } else {
                        this.$message.warning('失败，请重新操作！')
                    }

                } else {
                    this.$message.warning('失败，请重新操作！')
                    return false
                }
            })
        },
        //确认发货
        async expressNum(data) {
            // console.log(this.express_num);
            let res = await this.$Http.expressNum(data)
            console.log(res);
            if (res.code == 200) {
                this.$message.success('快递信息录入！');
                // this.getOrderList()
                this.show = false
                this.form = {
                    id: '',
                    express: '',
                    express_num: ''
                }
                this.$emit('reloadFun')
            }
        },
    }
}
</script>

<style lang="sass" scoped>

</style>